const { DataTypes } = require('sequelize')
const sequelize = require('../config/database')

const OrderModel = sequelize.define('Order', {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    allowNull: false,
    primaryKey: true
  },
  property_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'property',
      key: 'id'
    }
  },
  user_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'user',
      key: 'id'
    }
  },
  user_name: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  user_phone: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  user_email: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  order_date: {
    type: DataTypes.DATE,
    allowNull: false,
  },
  user_remarks: {
    type: DataTypes.STRING
  },
  status: {
    type: DataTypes.ENUM('待处理', '同意', '拒绝', '已完成'),
    allowNull: false,
    defaultValue: '待处理'
  },
  createdAt: {
    type: DataTypes.TIME
  },
  updatedAt: {
    type: DataTypes.TIME,
  }
}, {
  freezeTableName: true,
  timestamps: false,
  tableName: 'order'
})


module.exports = OrderModel